<template>
  <a-tree-select
      v-model:value="value"
      show-search
      style="width: 100%"
      :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
      placeholder="请选择"
      allow-clear
      :tree-data="list"
      tree-default-expand-all
      :field-names="{ children: 'children', label:'orgName', value:'id' }"
  />
</template>
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { SysOrg } from '@/config/common'
import { getOrgs } from '@/api/sys-org'

const props = defineProps({
  modelValue: String
})

const value = computed({
  set: val => emits('update:modelValue', val),
  get: () => props.modelValue
})
const emits = defineEmits(['update:modelValue'])

const list = ref<SysOrg[]>([])

const loadData = async () => {
  list.value = await getOrgs()
}

loadData()
</script>
